package cate.common.table.item;

import cate.common.table.ERow;
import cate.common.table.XSSFRowWrap;
import cate.common.table.d.GDCamp;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import org.apache.commons.lang3.StringUtils;

import java.util.HashSet;
import java.util.Set;

@NoteClass(value = "升星道具")
public class StarUpItemRow extends ERow {

    @NoteField(value = "物品ID")
    public int itemId;

    @NoteField(value = "阵营")
    private String campStr;

    @NoteField(value = "星级")
    public int star;

    @Override
    public void parse(XSSFRowWrap xr) {
        this.id = xr.getInteger("物品ID", 0);
        this.itemId = xr.getInteger("物品ID", 0);
        this.campStr = xr.getString("阵营");
        this.star = xr.getInteger("星级", 0);
    }

    public Set<Byte> camps = new HashSet<>();

    @Override
    public void decode() {
        if (StringUtils.isNotBlank(campStr)) {
            int idx = campStr.length();
            while(--idx >= 0){
                camps.add(Byte.valueOf(String.valueOf(campStr.charAt(idx))));
            }
        }
    }

    /**
     * 该升星道具是否可以替代 指定阵营的英雄
     * @param camp
     * @return
     */
    public boolean replaceCampValid(byte camp) {
        if (camps.contains(GDCamp.Type.NULL)) {
            return true;
        }
        return camps.contains(camp);
    }
}
